package com.wujunshen.algorithm.leetcode.basic;

/**
 * @author frank woo(吴峻申) <br>
 *     email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/7/25 10:47<br>
 */
public class 寻找旋转排序数组中的最小值II {
  public int findMin(int[] nums) {
    int n = nums.length;
    if (nums[0] < nums[n - 1]) {
      return nums[0];
    }
    int left = 0;
    int right = n - 1;
    while (left != right) {
      int mid = left + (right - left) / 2;
      if (nums[mid] > nums[right]) {
        left = mid + 1;
      } else if (nums[mid] < nums[right]) {
        right = mid;
      } else {
        right = right - 1;
      }
    }
    return nums[left];
  }
}
